package com.school.graduation.test;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.school.graduation.R;

import java.util.List;

public class SortListAdapter extends ArrayAdapter<String> {

    private List<String> sorts;

    public SortListAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<String> objects) {
        super(context, resource, objects);
        sorts = objects;
    }

    @Override
    public int getCount() {
        return sorts.size();
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView==null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_spinner_sort,parent,false);
            viewHolder.content = (TextView) convertView.findViewById(R.id.item_sort_text);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.content.setText(sorts.get(position));
        return convertView;
    }

    class ViewHolder{
        TextView content;
    }
}
